/*
 *  PureTemperatmenTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/10/02.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "PureTemperatmenTester.h"
#include "../Common/PureTemperament.h"
#include "CustomAssert.h"

namespace sc
{
	void PureTemperatmenTester::TestAll()
	{
		Test_GetIntervalRate();
	}

	void PureTemperatmenTester::Test_GetIntervalRate()
	{
		Test_GetIntervalRate_0000();
		Test_GetIntervalRate_0001();
		Test_GetIntervalRate_0002();
		Test_GetIntervalRate_0003();
	}

	void PureTemperatmenTester::Test_GetIntervalRate_0000()
	{	
		//	1 oct 内の音程差試験
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::A ), 1.0 );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::ASharp ), 16.0 / 15.0 );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::BFlat ), 16.0 / 15.0 );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::B ), 9. / 8. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::Note::CFlat ), 9.0 / 8.0 );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::C ), 6. / 5. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::Note::BSharp ), 6. / 5. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::CSharp ), 5. / 4. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::DFlat ), 5. / 4. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::D ), 4. / 3. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::DSharp ), 7. / 5. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::EFlat ), 7. / 5. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::E ), 3. / 2. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::FFlat ), 3. / 2. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::F ), 8. / 5. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::ESharp ), 8. / 5.  );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::FSharp ), 5. / 3. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::GFlat ), 5. / 3. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::G ), 16. / 9. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::GSharp ), 15.0 / 8.0 );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, Note::AFlat ), 15.0 / 8.0 );

		//	Db中心で同様に試験
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::A ), 8. / 5. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::ASharp ), 5. / 3. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::BFlat ), 5. / 3. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::B ), 16. / 9. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::CFlat ), 16. / 9.0 );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::C ), 15. / 8. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::BSharp ), 15. / 8. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::CSharp ), 1. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::DFlat ), 1 );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::D ), 16. / 15. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::DSharp ), 9. / 8. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::EFlat ), 9. / 8. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::E ), 6. / 5. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::FFlat ), 6. / 5. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::F ), 5. / 4 );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::ESharp ), 5. / 4. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::FSharp ), 4. / 3. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::GFlat ), 4. / 3. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::G ), 7. / 5. );

		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::GSharp ), 3. / 2. );
		AssertEqual( PureTemperament::GetIntervalRate( Note::DFlat, Note::AFlat ), 3. / 2. );

	}

	void PureTemperatmenTester::Test_GetIntervalRate_0001()
	{
		//	１オクターブ内の音を試験

		//	同度
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::A, 0 ), 1 );

		//	A0 Ab0 => m2th up 
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::Note::ASharp, 0 ), 16. / 15. );

		//	Ab0 A0 => m2th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, 0, Note::A, 0 ), 15. / 16. );

		//	Eb0 A0 => a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, 0, Note::A, 0 ), 7. / 10. );

		//	Eb0 A1 => a4th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, 0, Note::A, 1 ), 7. / 5. );
		
		//	A0 Eb0 => a4th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::EFlat, 0 ), 7. / 5. );

		//	A0 Eb-1 => a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::EFlat, -1 ), 7. / 10. );


		//	A0 Ab0 => m2th up 
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 1, Note::Note::ASharp, 1 ), 16. / 15. );

		//	Ab0 A0 => m2th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, 1, Note::A, 1 ), 15. / 16. );

		//	Eb0 A0 => a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, 1, Note::A, 1 ), 7. / 10. );

		//	Eb0 A1 => a4th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, 1, Note::A, 2 ), 7. / 5. );
		
		//	A0 Eb0 => a4th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 1, Note::EFlat, 1 ), 7. / 5. );

		//	A0 Eb-1 => a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 1, Note::EFlat, 0 ), 7. / 10. );


		//	A0 Ab0 => m2th up 
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, -1, Note::Note::ASharp, -1 ), 16. / 15. );

		//	Ab0 A0 => m2th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, -1, Note::A, -1 ), 15. / 16. );

		//	Eb0 A0 => a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, -1, Note::A, -1 ), 7. / 10. );

		//	Eb0 A1 => a4th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, -1, Note::A, 0 ), 7. / 5. );
		
		//	A0 Eb0 => a4th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, -1, Note::EFlat, -1 ), 7. / 5. );

		//	A0 Eb-1 => a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, -1, Note::EFlat, -2 ), 7. / 10. );

	}

	void PureTemperatmenTester::Test_GetIntervalRate_0002()
	{
		//	オクターブを超える音程を試験

		//	同度
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::A, 1 ), 2 );
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::A, -1 ), 1. / 2 );

		//	A0 Ab0 =>  1 oct + m2th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::Note::ASharp, 1 ), 32. / 15. );

		//	A0 Ab0 =>  - 1 oct + m2th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 0, Note::Note::ASharp, -1 ), 8. / 15. );

		//	Ab0 A0 => M7th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, 0, Note::A, 1 ), 15. / 8. );

		//	Ab0 A0 => -1 oct - m2th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, 0, Note::A, -1 ), 15. / 32. );

		//	Eb0 A0 => - 1 oct + a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, 0, Note::A, -1 ), 7. / 20. );


		//	A0 Ab0 =>  1 oct + m2th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 1, Note::Note::ASharp, 2 ), 32. / 15. );

		//	A0 Ab0 =>  - 1 oct + m2th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, 1, Note::Note::ASharp, 0 ), 8. / 15. );

		//	Ab0 A0 => M7th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, 1, Note::A, 2 ), 15. / 8. );

		//	Ab0 A0 => -1 oct - m2th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, 1, Note::A, 0 ), 15. / 32. );

		//	Eb0 A0 => - 1 oct + a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::EFlat, 1, Note::A, 0 ), 7. / 20. );

		
		//	A0 Ab0 =>  1 oct + m2th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, -1, Note::Note::ASharp, 0 ), 32. / 15. );

		//	A0 Ab0 =>  - 1 oct + m2th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::A, -1, Note::Note::ASharp, -2 ), 8. / 15. );

		//	Ab0 A0 => M7th up
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, -1, Note::A, 0 ), 15. / 8. );

		//	Ab0 A0 => -1 oct - m2th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::Note::ASharp, -1, Note::A, -2 ), 15. / 32. );

		//	Eb0 A0 => - 1 oct + a4th down
		AssertEqual( PureTemperament::GetIntervalRate( Note::EFlat, -1, Note::A, -2 ), 7. / 20. );
		

	}

	void PureTemperatmenTester::Test_GetIntervalRate_0003()
	{
	}

}